<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('系统管理员操作界面')"/>
    <link th:href="@{/ruoyi/css/font-awesome.css}" rel="stylesheet"/>
    <link th:href="@{/ruoyi/css/jquery-confirm.min.css}" rel="stylesheet"/>
</head>
<style type="text/css">

    .add_jjfa {
        background-color: #1e84c5;
        color: #FFFFFF;
    }
    .add_yg{
        background-color: #1e84c5;
        color: #FFFFFF;
    }
    .table {
        table-layout: fixed;
    }
    #macdz_id {
        width: 250px;
        height: 32px;
        margin-right: 50px;
        float: right;
        border: none;
        border-bottom: 1px solid #e5e6e7;
    }
    #macdz_id > input {
        height: 21px;
        width: 26.3px;
        border: none;
        text-align: center;
    }
    #macdz_id > input[readonly] {
        background-color: #EEEEEE;
    }
    #ipdz_id {
        width: 250px;
        margin-right: 50px;
        height: 32px;
        float: right;
        border: none;
        border-bottom: 1px solid #e5e6e7;
    }
    #ipdz_id > input {
        height: 21px;
        width: 32.3px;
        border: none;
        text-align: center;
    }
    #ipdz_id > input[readonly] {
        background-color: #EEEEEE;
    }

</style>
<body class="gray-bg" style="width: 95%;margin: 0px auto">

<!--添加解决方案模态框开始-->
<div class="tjjjfa">
    <div class="modal fade" id="tjjjfaModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         data-backdrop="static" data-keyboard="false">
        <div class="modal-dialog modal-xl" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="tjModalLabel">添加解决方案</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal">
                        <div class="form-group" style="display: none">
                            <label class="col-sm-2 control-label">生成ID</label>
                            <div class="col-sm-8">
                                <input type="text" name="gsid" class="form-control" id="gsid_jjfa"
                                       placeholder="请点击生成ID号">
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2">故障分类</label>
                            <div class="col-sm-10">
                                <select name="gzfl" class="form-control m-b" id="gzfl">
                                </select>
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2">故障原因</label>
                            <div class="col-sm-10">
                                <input name="gzyy" id="gzyy_fl" class="form-control" list="browsersforgzyy">
                                <datalist id="browsersforgzyy"></datalist>
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2">解决方案</label>
                            <div class="col-sm-10">
                                <input type="text" name="jjfa" class="form-control" id="jjfa_name"
                                       placeholder="请输入解决方案">
                                <span class="help-block"></span>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="tj_jjfa_btn" onclick="tjjjfa()">添加</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!--添加解决方案模态框结束-->

<div class="container-div">
    <form class="form-horizontal" id="sbwhform">
        <div class="row">
            <div class="form-group">
                <h1><strong>维护设备</strong></h1>
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-2 control-label">设备id号(隐藏)</label>
            <div class="col-sm-10">
                <input type="text" name="gsid" class="form-control" id="gsid_update_input_15">
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-2 control-label">设备id号(隐藏)</label>
            <div class="col-sm-10">
                <input type="text" name="whrq" class="form-control" id="whrq_update_input_15">
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-2 control-label">设备编号(隐藏)</label>
            <div class="col-sm-10">
                <input type="text" name="sbbh" class="form-control" id="sbbh_update_input_15">
                <span class="help-block"></span>
            </div>
        </div>
        <div class="row">
            <div class="form-group">
                <label class="col-sm-2 control-label top_lab">故障分类</label>
                <div class="col-sm-10" id="gzfl_div">
                    <select name="gzfl" class="form-control" style="width: 80%;float: right;margin: -40px 0px 0px 0px" id="gzfl_update_input_15">
                        <option value="0">请选择解决方案</option>
                    </select>
                    <span class="help-block"></span>
                </div>
            </div>
        </div>
        <div class="row">
        <div class="form-group">
            <label class="col-sm-2 control-label">故障原因</label>
            <div class="col-sm-10" id="gzyy_div">
                <select name="gzyy" class="form-control" style="width: 80%;float: right;margin: -40px 0px 0px 0px" id="gzyy_update_input_15">
                    <option value="0">请选择故障原因</option>
                </select>
                <span class="help-block"></span>
            </div>
        </div>
        </div>

        <div class="row">
        <div class="form-group">
            <label class="col-sm-2 control-label">解决方案</label>
            <div class="col-sm-7" id="jjfa_div">
                <select name="jjfa" class="form-control" id="jjfa_update_input_15" style="width: 45%;float: right;margin: -13% 35% 0px 0px">
                    <option value="0">请选择解决方案</option>
                </select>
                <span class="help-block"></span>
            </div>
            <input type="hidden" name="whjl" id="whjl_input">
            <input type="hidden" name="whlb" id="whlb_input">
            <input type="hidden" name="whjlbh" id="whjlbh_input">
            <div class="col-sm-2" id="add_jjfa_div" style="width: 40%;float: right;margin: -13% 0px 0px 0px;">
                <button type="button" class="btn btn-white add_jjfa">添加解决方案</button>
            </div>
        </div>
        </div>
        <div class="row">
        <div class="form-group">
            <label class="col-sm-2 control-label">部门名称</label>
            <div class="col-sm-4" id="selbm_div">
                <select name="bm" class="form-control" id="selectbm" style="width: 80%;float: right;margin: -10% 0px 0px 0px">
                </select>
                <!--<input name="bm" id="selectbm" style="background-color: #FFFFFF" class="form-control" list="browsersbybm"><datalist id="browsersbybm"></datalist>-->
                <input type="hidden" id="bmmc_hidden">
                <input type="hidden" id="ybmmc" name="ybm">
            </div></div></div>
            <div class="row">
                <div class="form-group">
            <label class="col-sm-2 control-label" id="shiyr_lab">使用人</label>
            <div class="col-sm-3">
                <input name="shiyr" id="shiyr01" style="background-color: #FFFFFF;width: 52%;float: right;margin: -10% 28% 0px 0px" class="form-control"
                       list="browsers">
                <datalist id="browsers"></datalist>
                <span class="help-block"></span>
                <input type="hidden" id="yshiyr" name="yshiyr">
            </div>
            <div class="col-sm-1" id="add_yg_div" style="float: right;margin: -10% 0px 0px 0px">
                <button type="button" class="btn btn-white add_yg" >人员管理</button>
            </div>
        </div></div>
        <div class="row">
        <div class="form-group">
            <label class="col-sm-2 control-label" id="weihr_lab" style="color: #9b9b9b">维护人：</label>
            <div class="col-sm-4" id="weihr_div" style="float: right;width: 82%;margin: -8% 0px 0px 0px">
                <input type="text" name="weihr" class="form-control" id="weihr_update_input_15"
                       style="color: #9b9b9b"
                       readonly="readonly">
            </div>
        </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" id="sbwh_insert_btn" onclick="savesbwh()">
                    保存
                </button>
            </div>
        </div>
    </form>
</div>
<div><input type="hidden" id="_pageNumber"></div>
<div><input type="hidden" id="_pageSize"></div>
<!--<p>[[${url}]]</p>-->
<div th:replace="zdyyj :: myfooter"></div>
<th:block th:include="include :: footer"/>
<script th:src="@{/ruoyi/js/jquery-confirm.min.js}"></script>
<script th:src="@{/ruoyi/js/jquery.form.js}"></script>
<script th:inline="javascript">
    var gsid="";
    var sessionname="";
    var sbbh="";
    $(document).ready(function () {
        gsid = [[${session.gsid}]]
        sessionname = [[${session.username}]]
        sbbh=[[${session.sbbh}]]
        if (sessionname==""){
            $.alert("当前状态未登陆系统或浏览器中当前会话结束了，您需要重新登陆","温馨提示")
            window.location.href = "/login";
        }

        $.ajax({
            url: "/sbgl/whflb/getgzfl/" + gsid,
            type: 'GET',
            success: function (data) {
                $('#gzfl_update_input_15').empty();
                var options = "";   //字符串拼接
                $("#gzfl_update_input_15").append('<option value="0">请选择故障分类</option>');
                for (var i in data) {  //遍历json数组
                    options += "<option value='" + data[i].gzfl + "'>" + data[i].gzfl + "</option>"
                    //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
                }
                $('#gzfl_update_input_15').append(options);
            }
        })

        $("#weihr_update_input_15").val(sessionname)
        getDepts("#selectbm");
        $.ajax({
            url: "/sbgl/sbxxb/getsbwh/" + sbbh + "/"+gsid,
            type: 'GET',
            async: false,
            success: function (data) {
                $("#selectbm").val(data[0].bm);
                $("#shiyr01").val(data[0].shiyr);
                $("#bmmc_hidden").val(data[0].bm);
                $("#gsid_update_input_15").val(gsid)
                $("#sbbh_update_input_15").val(sbbh)
                $("#gzyy_update_input_15").val(0)
                $("#ybmmc").val(data[0].bm)
                $("#yshiyr").val(data[0].shiyr)
                $('#whrq_update_input_15').val(getdate)
            }
        })
    });

    $('#gzfl_update_input_15').change(function () {
        var sbwhid = $("#gzfl_update_input_15 option:selected").val();
        $.ajax({
            url: "/sbgl/whflb/getgzyyforid/" + gsid + "/" + sbwhid,
            type: 'GET',
            async: false,
            success: function (data) {
                $('#gzyy_update_input_15').empty();
                var options = "";   //字符串拼接
                $("#gzyy_update_input_15").append('<option value="0">请选择故障原因</option>');
                for (var i in data) {  //遍历json数组
                    options += "<option value='" + data[i].gzyy + "'>" + data[i].gzyy + "</option>"
                    //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
                }
                $('#gzyy_update_input_15').append(options);
            }

        })
    })

    $('#gzyy_update_input_15').change(function () {
        var sbwhid = $("#gzyy_update_input_15 option:selected").val();
        $.ajax({
            url: "/sbgl/whflb/getjjfa/" + sbwhid + "/" + gsid,
            type: 'GET',
            async: false,
            success: function (data) {
                $('#jjfa_update_input_15').empty();
                var options = "";   //字符串拼接
                $("#jjfa_update_input_15").append('<option value="0">请选择解决方案</option>');
                for (var i in data) {  //遍历json数组
                    options += "<option value='" + data[i].jjfa + "'>" + data[i].jjfa + "</option>"
                    //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
                }
                $('#jjfa_update_input_15').append(options);
            }
        })
    })
    function getDepts(ele) {
        $.ajax({
            url: "/sbgl/ygxxb/getbm/" + gsid,
            type: 'get',
            async: false,
            success: function (data) {
                $(ele).empty();
                var options = "";   //字符串拼接
                $(ele).append('<option value="">请选择部门</option>');
                for (var i in data) {  //遍历json数组
                    options += "<option value='" + data[i].bm + "'>" + data[i].bm + "</option>"
                    //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
                }
                $(ele).append(options);
            },
        });
    };

    function confirm(title,content,ele) {
        $.confirm({
            title: title,
            content: content,
            buttons: {
                确定: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function(){
                        $(ele).modal('hide');
                    }
                }
            }
        });
    }

    $('.add_jjfa').click(function () {
        $("#gsid_jjfa").val(gsid);
        $("#tjjjfaModal").modal({
            backdrop: "static"
        });
        $.ajax({
            url: "/sbgl/whflb/getgzfl/" + gsid,
            type: 'GET',
            async: false,
            success: function (data) {
                $('#gzfl').empty();
                var options = "";   //字符串拼接
                $("#gzfl").append('<option value="">请选择故障分类</option>');
                for (var i in data) {  //遍历json数组
                    options += "<option value='" + data[i].gzfl + "'>" + data[i].gzfl + "</option>"
                    //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
                }
                $('#gzfl').append(options);
            }
        })
    });

    $('.add_yg').click(function () {
        $.confirm({
            title: '人员管理!',
            content: '新添加员工请选择新增人员，使用人变更部门请选择人员变更，变更前一定要在上一个页面中选择部门',
            buttons: {
                confirm: {
                    text: '新增人员',
                    btnClass: 'btn-blue',
                    action: function () {
                        var bmid = $("#selectbm option:selected").val();
                        if (bmid == "0") {
                            $.alert("您在上个页面未选择部门，请关闭当前页面后选择使用人所在的部门","温馨提示")
                        } else {
                            $('#myModal5').modal('toggle');
                            $.confirm({
                                title: '新增人员',
                                content: '' +
                                    '<form action="" class="formName">' +
                                    '<div class="form-group">' +
                                    '<div class=""><label>部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;门：</label>' +
                                    '<input type="text" placeholder="请输入部门名称" readonly="readonly" class="bmmc" style="width: 80%;"/><input type="hidden" placeholder="请输入部门名称" name="bm" id="bmid_con"/></div>' +
                                    '<div class="" style="margin-top: 10px"><label>人员姓名：</label>' +
                                    '<input type="text" placeholder="请输入新增人员的姓名" id="yg_xingm" name="shiyr" style="width: 80%;" class="shiyr"/><input type="hidden" name="gsid" id="gsid_tj"></div>' +
                                    '</div>' +
                                    '<div class="" style="margin-top: -5px"><label>登录账号：</label>' +
                                    '<input type="text" placeholder="请输入新增人员的姓名" id="denglzh" name="loginName" style="width: 80%;" class="lgname"/></div>' +
                                    '</div>' +
                                    '<div class="" style="display: none"><label>登录密码：</label>' +
                                    '<input type="text" placeholder="请输入新增人员的姓名" id="denglmm" name="loginPassword" value="admin" style="width: 80%;" class="lgpassword"/></div>' +
                                    '</div>' +
                                    '</form>',
                                buttons: {
                                    确定: {
                                        text: '确定',
                                        btnClass: 'btn-blue',
                                        action: function () {
                                            var name = this.$content.find('.shiyr').val();
                                            var lgname = this.$content.find('.lgname').val();
                                            var bm = $("#bmid_con").val()
                                            if (!name || !lgname) {
                                                $.alert('您未输入人员姓名或登录账号，请认真输入', "温馨提示");
                                                return false
                                            }
                                            var isygxxb = cfpd("/sbgl/ygxxb/getygxxb/", gsid)
                                            var isshiyr = panduan("/sbgl/ygxxb/getbmbyshiyrandbm/",name,bm,gsid)
                                            var bms=[]
                                            var names=[]
                                            var lgnames=[]
                                            for (var i in isygxxb){
                                                if (bms.indexOf(bm) == -1) {
                                                    bms.push(isygxxb[i].bm)
                                                }
                                                names.push(isygxxb[i].shiyr)
                                                lgnames.push(isygxxb[i].loginName)
                                            }
                                            if (lgnames.indexOf(lgname)>=0) {
                                                $.alert("登录账号重复了","温馨提示")
                                                return false
                                            }
                                            if (isshiyr!='全公司上下查无此人'){
                                                $.alert("该员工信息已存在，若要继续添加联系系统管理员","温馨提示")
                                                return false
                                            }
                                            return $.ajax({
                                                url: '/sbgl/ygxxb/insertyg',
                                                async: false,
                                                method: 'POST',
                                                data: $(".formName").serialize(),
                                            }).done(function (data) {
                                                $.confirm({
                                                    title: '温馨提示!',
                                                    content: '添加人员成功',
                                                    buttons: {
                                                        确定: {
                                                            text: '确定',
                                                            btnClass: 'btn-blue',
                                                            action: function () {
                                                                window.location.href=window.location.href
                                                            }
                                                        },
                                                    }
                                                });
                                            }).fail(function () {
                                            })
                                        }
                                    },
                                    // cancel: function () {
                                    //     //close
                                    // },
                                    取消:{
                                        text: '取消',
                                        btnClass: 'btn-blue',
                                        action: function () {
                                        }
                                    }
                                },
                                onContentReady: function () {
                                    var bmid = $("#selectbm option:selected").val();
                                    var sbbh=($("#sbbh_update_input_15").val())
                                    var bm=cfpd("/sbgl/sbxxb/getbm/",sbbh)
                                    $('.bmmc').val(bm)
                                    $("#bmid_con").val(bm)
                                    $("#gsid_tj").val(gsid)
                                }
                            });
                        }
                    }
                },
                yrbd: {
                    text: '人员变动',
                    btnClass: 'btn-blue',
                    action: function () {
                        var bmid = $("#selectbm option:selected").val();
                        if (bmid == "0") {
                            $.alert("您在上个页面未选择部门，请关闭当前页面后选择使用人所在的部门","温馨提示")
                        } else {
                            $.confirm({
                                title: '人员变动',
                                content: '' +
                                    '<form action="" class="shiyrformName">' +
                                    '<div class="form-group">' +
                                    '<div class=""><label>原部门：</label>' +
                                    '<input type="text" readonly="readonly" placeholder="请输入部门名称" class="bmmc"/><input type="hidden" placeholder="请输入部门名称" id="bmid_con"/></div>' +
                                    '<div class=""><label>使用人：</label>' +
                                    '<input type="text" readonly="readonly" placeholder="请输入新增人员的姓名" id="yxingm"/><input type="hidden" id="shiyr_sbbh" name="sbbh"/></div>' +
                                    '<div class=""><label>现部门：</label>' +
                                    '<select type="text" id="xxingm" name="bm" style="width: 72%"></select></div>' +
                                    '</div>' +
                                    '</form>',
                                buttons: {
                                    formSubmit: {
                                        text: '确定',
                                        btnClass: 'btn-blue',
                                        action: function () {
                                            var xbmid = $("#xxingm option:selected").val();//得到部门ID
                                            var yxingm = $("#yxingm").val()
                                            if (!xbmid) {
                                                $.alert('您未选择使用人的部门，请选择',"温馨提示");
                                                return false
                                            } else {
                                                return $.ajax({
                                                    url: '/sbgl/ygxxb/updateygxxb/' + yxingm,
                                                    dataType: 'json',
                                                    method: 'PUT',
                                                    data: $(".shiyrformName").serialize(),
                                                }).done(function (data) {
                                                    // $.ajax("更新成功！！！");
                                                    updatesbxxbbywh(sbbh)
                                                    $("#selectbm").val(xbmid)
                                                    window.location.href = window.location.href;
                                                })
                                            }
                                        }
                                    },
                                    cancel:{
                                        text: '取消',
                                        btnClass: 'btn-blue',
                                    },
                                },
                                onContentReady: function () {
                                    var sbbh=($("#sbbh_update_input_15").val())
                                    var shiyr=cfpd("/sbgl/sbxxb/getshiyrbysbbh/",sbbh)
                                    var bm=cfpd("/sbgl/sbxxb/getbm/",sbbh)
                                    var bmid = $("#selectbm option:selected").val();
                                    $("#yxingm").val(shiyr)
                                    $('.bmmc').val(bm)
                                    $("#bmid_con").val(bm)
                                    $("#shiyr_sbbh").val(sbbh);
                                    return $.ajax({
                                        url: '/sbgl/ygxxb/getbm/' + gsid,
                                        dataType: 'json',
                                        method: 'get',
                                    }).done(function (data) {
                                        $('#xxingm').empty();
                                        var options = "";   //字符串拼接
                                        $('#xxingm').append('<option value="">请选择部门</option>');
                                        for (var i in data) {  //遍历json数组
                                            options += "<option value='" + data[i].bm + "'>" + data[i].bm + "</option>"
                                            //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
                                        }
                                        $('#xxingm').append(options);
                                    })
                                }
                            });
                        }
                    }
                },
                cancel:{
                    text: '取消',
                    btnClass: 'btn-blue',
                },
            }
        });
    });

    //通过部门id获取部门名称
    function getbmmcsjk(bmid) {
        var bmmc = ""
        $.ajax({
            url: "/sbgl/ygxxb/getbmmc/" + bmid,
            type: 'GET',
            async: false,
            success: function (result) {
                if (result != null) {
                    bmmc = result.replace(/\s+/g, "");
                    // result.replace(/\s+/g,"");替换所有空格
                    // result.replace(/^\s+|\s+$/g,"");替换前后空格
                }
            }
        });
        return bmmc;
    }

    //通过设备编号更新设备信息表(不同form)
    function updatesbxxbbywh(sbbh) {
        $.ajax({
            url: "/sbgl/sbxxb/updatesbxxbbywh/" + sbbh,
            type: "put",
            async: false,
            data: $(".shiyrformName").serialize(),
            success: function (data) {
            }
        })
    }
    $('#selectbm').change(function () {
        var bmid = $("#selectbm option:selected").val();
        $('#shiyr01').val("");
        $('#browsers').empty();
        $("#shiyr01").removeAttr("readonly")
        $.ajax({
            url: "/sbgl/ygxxb/getygxx/" + bmid+"/"+gsid,
            type: 'get',
            success: function (data) {
                $('#shiyr01').empty();
                var options = "";   //字符串拼接
                for (var i in data) {  //遍历json数组
                    options += "<option value='" + data[i].shiyr + "'>" + data[i].zjm + "</option>"
                    //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
                }
                $('#browsers').append(options);
            },
        });
    });
    $('#gzyy_update_input_15').change(function () {
        var sbwhid = $("#gzyy_update_input_15 option:selected").val();
        $.ajax({
            url: "/sbgl/whflb/getjjfa/" + sbwhid + "/" + gsid,
            type: 'GET',
            async: false,
            success: function (data) {
                $('#jjfa_update_input_15').empty();
                var options = "";   //字符串拼接
                $("#jjfa_update_input_15").append('<option value="0">请选择解决方案</option>');
                for (var i in data) {  //遍历json数组
                    options += "<option value='" + data[i].jjfa + "'>" + data[i].jjfa + "</option>"
                    //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
                }
                $('#jjfa_update_input_15').append(options);
            }

        })
    })

    $("#gzfl").change(function () {
        var gzfl = $('#gzfl').val();
        $.ajax({
            url: "/sbgl/whflb/getgzyybyfl/" + gsid + "/" + gzfl,
            type: 'GET',
            async: false,
            success: function (data) {
                $('#gzyy_fl').empty();
                $('#browsersforgzyy').empty();
                var options = "";   //字符串拼接
                for (var i in data) {  //遍历json数组
                    options += "<option value='" + data[i] + "'>" + data[i] + "</option>"
                    //     // "<input type='radio' class='roles' name='roles' id='"+data[i].wjdcs+"' value='"+data[i].wjdc+"'>"+data[i].wjdc+"&nbsp;&nbsp;"
                }
                $('#browsersforgzyy').append(options);
            },
        })
    })

    // 获取当前日期
    function getdate() {
        var d = new Date();
        var y = d.getFullYear();
        var m = d.getMonth() + 1;
        var d = d.getDate();
        if (m < 10) m = "0" + m;
        if (d < 10) d = "0" + d;
        return y + "-" + m + "-" + d
    }

    $("#jjfa_update_input_15").change(function () {
        var gzyy = $("#gzyy_update_input_15 option:selected").text();
        var jjfa = $("#jjfa_update_input_15 option:selected").text();
        var index = gzyy.lastIndexOf("\/");
        gzyy = gzyy.substring(index + 1, gzyy.length);
        $("#whjl_input").val("该设备" + getdate() + "由于" + gzyy + "进行设备维护，维护方法为" + jjfa)
    })

    //我之前做的保存维护记录开始
    function savesbwh() {
        var bmid = $("#selectbm option:selected").val();//新的部门id
        var bmmc = $("#selectbm option:selected").text().replace(/\s+/g, "");//新的部门名称
        var shiyr = $("#shiyr01").val();//新的设备使用人
        var bmmc_hidden = $("#bmmc_hidden").val();//原部门id（隐藏的）
        var shiyr_sjk = getshiyr(sbbh)
        var bmid_sjk = getbmid(sbbh);
        var bmmc_sjk = getbmmcsjk(bmmc_hidden);
        var gzyy = $("#gzyy_update_input_15 option:selected").val()
        var jjfa = $("#jjfa_update_input_15 option:selected").val()
        var gzyyT = $("#gzyy_update_input_15 option:selected").text()
        var jjfaT = $("#jjfa_update_input_15 option:selected").text()
        var bmidbyshiyr = "";
        if (shiyr === "" && bmid != bmid_sjk && gzyy == "0") {
            // alert("部门、使用人未改变,故障原因改变了，这里需要提醒请选择解决方案")
            $.alert("使用人不能为空","温馨提示")
            return false
            // var bmidbyshiyr = getdeptbyshiyr(shiyr)
        } else if (shiyr === "" && bmid === bmid_sjk && gzyy == "0") {
            $.alert("使用人不能为空，整个页面你没有进行操作，不能点击保存","温馨提示")
            return false
        } else if (shiyr === "" && bmid != bmid_sjk && gzyy != "0" && jjfa == "0") {
            $.alert("使用人不能为空，解决方案不能为空","温馨提示")
            return false
        } else if (shiyr === "" && bmid != bmid_sjk && gzyy != "0" && jjfa != "") {
            $.alert("使用人不能为空","温馨提示")
            return false
        } else {
            //部门和使用人相同
            if (shiyr == shiyr_sjk && bmid == bmid_sjk && gzyy == "0") {
                // alert("部门、使用人、故障原因、解决方案都未改变，这里不需要插入任何数据")
                $.alert("你未进行任何操作，不必添加任何的维护记录，你最起码要修改点数据吧！！！","温馨提示")
            }

            if (shiyr == shiyr_sjk && bmid == bmid_sjk && gzyy != "0" && jjfa == "0") {
                // alert("部门、使用人未改变,故障原因改变了，这里需要提醒请选择解决方案")
                $.alert("请选择解决方案","温馨提示")
            }

            if (shiyr == shiyr_sjk && bmid == bmid_sjk && gzyy != "0" && jjfa != "0") {
                // alert("部门、使用人未改变,故障原因、解决方案改变，这里需要插入一条故障原因与解决方案的维护记录")
                $("#whlb_input").val("系统维护")
                insertsbwhb()
            }
            //部门使用人都维护了
            if (shiyr != shiyr_sjk && bmid != bmid_sjk && gzyy == "0") {
                // alert("部门和使用人修改了，故障原因与解决方案未选择，这里插入一条部门与使用人维护的一条记录")
                bmidbyshiyr = getdeptbyshiyr(shiyr)
                if (bmidbyshiyr != bmid) {
                    $.alert("此部门查无此人，请核对或点击人员管理","温馨提示")
                } else {
                    alert(999999)
                    $.alert("应该进入这里啊","温馨提示")
                    $("#whjl_input").val("该设备" + getdate() + "的使用部门由" + bmmc_sjk + "-" + shiyr_sjk + "维护成" + bmmc + "-" + shiyr)
                    $("#whlb_input").val("系统维护")
                    updatesbxxb(sbbh);
                    insertsbwhb()
                }
            }

            if (shiyr != shiyr_sjk && bmid != bmid_sjk && gzyy != "0" && jjfa == "0") {
                // alert("部门和使用人修改了，故障原因选择了，提示请选择解决方案")
                $.alert("请选择解决方案","温馨提示");
            }

            if (shiyr != shiyr_sjk && bmid != bmid_sjk && gzyy != "0" && jjfa != "0") {
                // alert("部门、使用人、故障原因、解决方案都修改了，这里需要插入2条记录，一条维护部门使用人，一条维护故障原因解决方案")
                bmidbyshiyr = getdeptbyshiyr(shiyr)
                if (bmidbyshiyr != bmid) {
                    $.alert("此部门查无此人，请核对或点击人员管理","温馨提示")
                } else {
                    alert(2131213123)
                    // $("#whjl_input").val("该设备" + getdate() + "的使用部门由" + bmmc_sjk + "-" + shiyr_sjk + "维护成" + bmmc + "-" + shiyr)
                    // $("#whlb_input").val("系统维护")
                    // updatesbxxb(sbbh);
                    // insertsbwhbnotgb()
                    // $("#whjl_input").val("该设备" + getdate() + "由于[" + gzyyT + "]进行设备维护，维护方法为[" + jjfaT + "]")
                    // insertsbwhb()
                }
            }

            if (shiyr != shiyr_sjk && bmid == bmid_sjk && gzyy != "0" && jjfa != "0") {
                // alert("部门、使用人、故障原因、解决方案都修改了，这里需要插入2条记录，一条维护部门使用人，一条维护故障原因解决方案")
                bmidbyshiyr = getdeptbyshiyr(shiyr)
                if (bmidbyshiyr != bmid) {
                    $.alert("此部门查无此人，请核对或点击人员管理","温馨提示")
                } else {
                    alert(66665555)
                    // $("#whjl_input").val("该设备" + getdate() + "的使用部门由" + bmmc_sjk + "-" + shiyr_sjk + "维护成" + bmmc + "-" + shiyr)
                    // $("#whlb_input").val("系统维护")
                    // updatesbxxb(sbbh);
                    // insertsbwhbnotgb()
                    // $("#whjl_input").val("该设备" + getdate() + "由于[" + gzyyT + "]进行设备维护，维护方法为[" + jjfaT + "]")
                    // insertsbwhb()
                }
            }

            if (shiyr != shiyr_sjk && bmid == bmid_sjk && gzyy == "0") {
                // alert("部门、使用人、故障原因、解决方案都修改了，这里需要插入2条记录，一条维护部门使用人，一条维护故障原因解决方案")
                bmidbyshiyr = getdeptbyshiyr(shiyr)
                if (bmidbyshiyr != bmid) {
                    $.alert("此部门查无此人，请核对或点击人员管理","温馨提示")
                } else {
                    alert(4444444)
                    // $("#whjl_input").val("该设备" + getdate() + "的使用部门由" + bmmc_sjk + "-" + shiyr_sjk + "维护成" + bmmc + "-" + shiyr)
                    // updatesbxxb(sbbh);
                    // $("#whlb_input").val("系统维护")
                    // insertsbwhb()
                }
            }
        }
    }

    //我之前做的保存维护记录结束

    function getshiyr(sbbh) {
        var shiyr = ""
        $.ajax({
            url: "/sbgl/sbxxb/getshiyr/" + sbbh + "/" + gsid,
            type: 'GET',
            async: false,
            success: function (result) {
                if (result != null) {
                    shiyr = result;
                }
            }
        })
        return shiyr
    }
    //通过设备编号获取原部门id
    function getbmid(sbbh) {
        var bmid = 0
        $.ajax({
            url: "/sbgl/sbxxb/getbmid/" + sbbh,
            type: 'GET',
            async: false,
            success: function (result) {
                bmid = result
            }
        });
        return bmid
    }
    // 通过设备编号更新设备信息表
    function updatesbxxb(sbbh) {
        $.ajax({
            url: "/sbgl/sbxxb/updatesbxxbbywh/" + sbbh,
            type: "put",
            async: false,
            data: $("#sbwhform").serialize(),
            success: function (data) {

            }
        })
    }
    // 插入设备维护表
    function insertsbwhb() {
        $.confirm({
            title: '温馨提示',
            content: '确定添加吗？？？',
            buttons: {
                OK: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function () {
                        return $.ajax({
                            url: "/sbgl/sbwhb/insertsbwh",
                            type: 'POST',
                            async: false,
                            data: $("#sbwhform").serialize(),
                        }).done(function (response) {
                            window.location.href = "/sbgl/sbxxb/sbwh/" + sbbh + '/';
                        }).fail(function () {
                        });
                    }
                },
                cancel: {
                    text: '取消',
                    btnClass: 'btn-red',
                    action: function () {
                    },
                },
            },
        });
    }
    // 插入设备维护表
    function insertsbwhbnotgb() {
        $.ajax({
            url: "/sbgl/sbwhb/insertsbwh",
            type: 'POST',
            async: false,
            data: $("#sbwhform").serialize(),
            success: function (result) {
                if (result != null) {
                }
            }
        });
    }

    function tjjjfa() {
        $.confirm({
            title: '温馨提示',
            content: '确定添加吗？？？',
            buttons: {
                确定: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function () {
                        return $.ajax({
                            url: '/sbgl/whflb/insertfl',
                            method: 'POST',
                            async: false,
                            data: $("#tjjjfaModal form").serialize()
                        }).done(function (response) {
                            window.location.href="/weihu"
                        }).fail(function () {
                        });
                    }
                },
                取消: {
                    text: '取消',
                    btnClass: 'btn-red',
                    action: function () {
                    },
                },
            },
        });
    };

    //通过使用人查询出部门的ID号
    function getdeptbyshiyr(shiyr) {
        var bmid = ""
        $.ajax({
            url: "/sbgl/ygxxb/getbmidbyshiyr/" + shiyr,
            type: 'GET',
            async: false,
            success: function (result) {
                bmid = result
            }
        });
        return bmid;
    }
</script>
</body>
</html>